<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务类型" >
              <a-select  v-model="queryParam.taskType" placeholder="请选择任务类型" allowClear>
                <a-select-option value="教师请假">
                  教师请假
                </a-select-option>
                <a-select-option value="拜访">
                  拜访
                </a-select-option>
                <a-select-option value="儿童请假">
                  儿童请假
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="status == 0"> 
            <a-form-item label="审批状态">
              <j-dict-select-tag type="list"  v-model="queryParam.taskApprovalState" dictCode="approval_state" placeholder="请选择审批状态" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24"  v-if="status == 1">
            <a-form-item label="发起人">
              <a-input v-model="queryParam.taskCreator" placeholder="请输入发起人姓名"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="status == 2">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="审核人">
                <a-input v-model="queryParam.taskApprovar" placeholder="请输入审核人姓名"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="审核结果">
                <j-dict-select-tag type="list"  v-model="queryParam.taskApprovalResult" dictCode="approval_result" placeholder="请选择审核结果" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator"  v-if="status == 0">
      <a-button @click="handleAdd" type="primary" icon="plus">请假</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="taskId"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <template v-if="(record.taskApprovalState == 2)&&status==0">
            <a @click="ApprovalAndDetail(record,2)">编辑</a>
            <a-divider type="vertical" />
          </template>
          <template v-if="!record.taskApprovalResult&&status == 1" >
            <a @click="ApprovalAndDetail(record,0)">审核</a>
            <a-divider type="vertical" />
          </template>
          <a @click="ApprovalAndDetail(record,1)">详情</a>
          <template v-if="status==0">
            <a-divider type="vertical" />
            <a-popconfirm  title="确定删除吗?" @confirm="() => handleDelete2(record)">
              <a>删除</a>
            </a-popconfirm>
          </template>
        </span>
      </a-table>
    </div>
    <sk-modal v-bind="$attrs" ref="modalForm" @ok="modalFormOk"></sk-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { deleteAction, getAction,downFile,getFileAccessHttpUrl } from '@/api/manage'
  import SkModal from "./skModal.vue";
import { functionsIn } from 'lodash';
import { queryById } from "@/api/management.js";
import {filterDictTextByCache} from '@/components/dict/JDictSelectUtil'
  export default {
    name: 'SkClassList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      SkModal
    },
    props:["status","url"],
    data () {
      return {
        description: '任务中心管理页面',
        teacherId:"",
        columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '任务类型',
          align: 'center',
          dataIndex: 'taskType'
        },
        {
          title: '任务发起人',
          align: 'center',
          dataIndex: 'taskCreator'
        },
        {
          title: '任务发起时间',
          align: 'center',
          sorter: true,
          dataIndex: 'taskCreateTime'
        },
        {
          title: '任务审核人',
          align: 'center',
          dataIndex: 'taskApprovar'
        },
        {
          title: '任务审核状态',
          align: 'center',
          dataIndex: 'taskApprovalState',
          customRender: function(text) {
            return filterDictTextByCache('approval_state', text)
          }
        },
        {
          title: '任务审核结果',
          align: 'center',
          dataIndex: 'taskApprovalResult',
          customRender: function(text) {
            return filterDictTextByCache('approval_result', text)
          }
        },
        {
          title: '任务审核时间',
          align: 'center',
          sorter: true,
          dataIndex: 'taskApprovalTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
        
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleDelete2(data){
        const url ="/task/delete"
        let params = {
          taskId:data.taskId,
          taskType:data.taskType
        }
        let that = this;
        deleteAction(url, params).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.reCalculatePage(1)
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      initDictConfig(){
      },
      // 审核和详情按钮
      ApprovalAndDetail(record,status){
        let url = "",result = {};
        if (record.taskType == "教师请假") {
          url = '/management/skStaffLeave/queryById'
        }
        if (record.taskType == "拜访") {
          url = '/management/skVisit/queryById'
        }
        if (record.taskType == "儿童请假") {
          url = '/management/skStudentLeave/queryById'
        }
        // 根据id查询教师请假信息
        let params = {
          id:record.taskId
        }
        queryById(url,params).then((res)=>{
          if(res.success){
            result = res.result;
            result.taskType = record.taskType;
            if (status == 1) {
              this.handleDetail(result);
            }else if (status == 2) {
              this.handleEdit(result);
            }else{
              this.handleApproval(result,true)
            }
          } else {
            this.$message.warning(error.message);
          }
        }).catch((error)=>{
          console.error(error);
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>